﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;

namespace RenjianImageViewer.ViewModel
{
    class SavingStateViewModel : DependencyObject
    {
        public static readonly DependencyProperty PositionProperty = DependencyProperty.Register(
          "Position", typeof(int), typeof(SavingStateViewModel), new PropertyMetadata(0));
        public static readonly DependencyProperty PercentageProperty = DependencyProperty.Register(
          "Percentage", typeof(double), typeof(SavingStateViewModel), new PropertyMetadata(0d));

        public int Position
        {
            get { return (int)this.GetValue(PositionProperty); }
            set { this.SetValue(PositionProperty, value); }
        }

        public double Percentage
        {
            get { return (double)this.GetValue(PercentageProperty); }
            set { this.SetValue(PercentageProperty, value); }
        }

        public bool ShowState { get; set; }
        public virtual int Count { get; set; }
    }

    class SavingMultiImageStateViewModel : SavingStateViewModel
    {
        private List<int> percentageList = new List<int>();
        public void SetPerentage(int index, int percentage)
        {
            percentageList[index] = percentage;
            Percentage = percentageList.Average();
        }

        public override int Count
        {
            get
            {
                return base.Count;
            }
            set
            {
                percentageList.AddRange(Enumerable.Repeat(0, value));
                base.Count = value;
            }
        }
    }
}
